package com.zmzncs.lmtc.module.promotion.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zmzncs.lmtc.common.annotation.Idempotent;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule.MonthRuleDTO;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_fee_scale.MonthRuleFeeScale;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_pull.MonthRulePullAddForm;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_pull.MonthRulePullDTO;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_pull.MonthRulePullTableVO;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_pull.MonthRulePullUpdateForm;
import com.zmzncs.lmtc.module.promotion.service.MonthRulePullService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 直联车场-月租规则 前端控制器
 * </p>
 *
 * @author 高博文
 * @since 2021-03-19
 */
@Api(tags = "停车场月租信息")
@RestController
@RequestMapping("/promotion/month-rule-pull")
public class MonthRulePullController {

    @Autowired
    MonthRulePullService monthRulePullService;


    @ApiOperation(value = "查询停车场信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(name = "page", value = "页码"),
            @ApiImplicitParam(name = "size", value = "每页记录数"),
            @ApiImplicitParam(name = "parkName", value = "车场名称"),
    })
    @PostMapping("getMonthRuleGroupByPark")
    public Rest<List<MonthRulePullTableVO>> getMonthRuleGroupByPark(Integer page, Integer size, String parkName){
        IPage<MonthRulePullTableVO> iPage = monthRulePullService.getMonthRuleGroupByPark(page,size,parkName);
        return RestUtil.success(iPage);
    }

    @ApiOperation(value = "根据车场ID查询停车场规则")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(name = "parkId", value = "车场Id", required = true),
    })
    @PostMapping("getParkMonthRuleByParkId")
    public Rest<List<MonthRulePullDTO>> getParkMonthRuleByParkId(@NotNull Long parkId){
        List<MonthRulePullDTO> list = monthRulePullService.getParkMonthRuleByParkId(parkId);
        return RestUtil.success(list);
    }

    @ApiOperation(value = "添加车场月租规则")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("add-month-rule")
    @Idempotent
    public Rest addMonthRule(@RequestBody @Validated MonthRulePullAddForm form){
         monthRulePullService.addMonthRule(form);

        return RestUtil.success();
    }

    @ApiOperation(value = "修改车场月租规则")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("update-month-rule")
    @Idempotent
    public Rest updateMonthRule(@RequestBody @Validated MonthRulePullUpdateForm form){
        monthRulePullService.updateMonthRule(form);

        return RestUtil.success();
    }

    @ApiOperation(value = "更新车场月租规则")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(name = "parkId", value = "车场Id", required = true),
    })
    @PostMapping("update-park-month-rule")
    @Idempotent
    public Rest updateParkMonthRule(@NotNull Long parkId){
        monthRulePullService.updateParkMonthRule(parkId);

        return RestUtil.success();
    }
}

